/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fontys.time;
import java.util.*;

/**
 *
 * @author Administrator
 */
public class Contact {
    String name;
    ArrayList<Appointment> agenda;
    
    /**
     * create a new contact
     * @param name the name of the contact
     */
    public Contact(String name){
       this.name = name;
       agenda = new ArrayList<Appointment>();
    }
    
    /**
     * Gets the name of this contact
     * @return a string containing the name
     */
    public String getName() {
        return name;
    }
    
    /**
     * Adds an appointment to the agenda.
     * @param a the appointment to add
     * @throws IllegalArgumentException whenever the new appointment overlaps
     * with an existing appointment
     */    
    void addAppointment(Appointment a){
        for(Appointment ap : agenda)
        {
            IPeriod intersection = a.getPeriod().intersectionWith(ap.getPeriod());
            if (intersection != null && intersection.length() != 0)
            {
               throw new IllegalArgumentException("appointment overlaps"
                       + "with some other appointment"); 
            }
        }
        agenda.add(a);
    }
    
    /**
     * Removes an appointment from the agenda.
     * If the appointment is not part of the agenda nothing happens
     * @param a the appointment to remove
     */
    void removeAppointMent(Appointment a){
        if (agenda.contains(a))
            agenda.remove(a);
    }
    
    /**
     * Get the agenda
     * @return all the appointments that where specified for this contact
     */
    public Iterator<Appointment> appointments() {
        return agenda.iterator();
    }
    
    
}
